package com.itheima.controller;


import com.itheima.common.JsonResult;
import com.itheima.common.SnowFlake;
import com.itheima.pojo.admin.Order;
import com.itheima.pojo.admin.Pagination;
import com.itheima.pojo.admin.orderdto.OrderPaginationDto;
import com.itheima.pojo.admin.orderdto.OrderStatusUpdateByIdDto;
import com.itheima.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @author ChenJunJie
 * @date 2022/6/13 16:22
 * 订单controller层
 */
@RestController
@RequestMapping(value = "/order", produces = "application/json;charset=utf-8")
public class OrderController {

    @Autowired
    private OrderService orderService;
    @Autowired
    private SnowFlake snowFlake;
    @Autowired
    private RedisTemplate<String, String> redisTemplate;


    // 订单分页查询
    @GetMapping("/page")
    public JsonResult<Pagination<Order>> orderPagination (OrderPaginationDto dto){
        return orderService.orderPagination(dto);
    }

    //修改订单状态
    @PutMapping
    public JsonResult<String> orderStatusUpdateById(@RequestBody OrderStatusUpdateByIdDto orderStatus){
        boolean b = orderService.orderStatusUpdateById(orderStatus);

        if (b){
            return JsonResult.success("修改成功");
        }else {
            return JsonResult.error("修改失败");
        }
    }
}
